﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using Sys.WebRes.Publish.Areas.Admin.Models;
using Sys.WebRes.Data;
using System.IO;
using System.Security.AccessControl;

namespace Sys.WebRes.Publish.Areas.Admin.Controllers
{
    /// <summary>
    /// 编辑媒体资源(一个媒体资源代表一组媒体)
    /// </summary>
    public partial class ResourceController
    {
        /// <summary>
        /// 获取媒体资源，或者新建媒体资源
        /// </summary>
        /// <param name="id"></param>
        /// <returns></returns>
        [HttpGet]
        public ActionResult EditMedias(int? id)
        {
            var model = GetFilesRes<MediasModel>(id, ResType.Media);
            return View(model);
        }

        /// <summary>
        /// 保存媒体资源
        /// </summary>
        /// <param name="model"></param>
        /// <returns></returns>
        [HttpPost]
        public ActionResult EditMedias(int? id, MediasModel model)
        {
            id = SaveFilesRes<MediasModel>(id, model, SysConfig.UploadFileFolder);
            return View(model);
        }

        /// <summary>
        /// 删除媒体资源
        /// </summary>
        /// <param name="id"></param>
        /// <returns></returns>
        [HttpPost]
        [ValidateInput(false)]
        public ActionResult DeleteMedias(int id)
        {
            DeleteFilesRes(id);
            return View(new MediasModel());
        }
    }
}